from threads import *
from queue import Queue
from tools.common_tools import toTimeStr


class Handler(threading.Thread):
    """
        操作线程方法
    """
    def __init__(self, results_queue):
        super(Handler, self).__init__()
        self.results_queue = results_queue
        self.__status = threading.Event()
        self.__status.set()

    def run(self):
        while self.__status.isSet():
            data = self.results_queue.get()
            print(toTimeStr(data.start_time) + " -> " + toTimeStr(data.end_time))
            print(data.en_text + " -> " + data.zh_text)
            print()

    def stop(self):
        self.__status.clear()

if __name__ == '__main__':
    frame_size = 256
    frame_shift = 128
    sr = 16000
    file_path = "E:/迅雷下载/videoplayback.wav"

    q1 = Queue(50)
    q2 = Queue(50)
    q3 = Queue(50)

    t1 = WaveAudio(q1, sr, frame_size, frame_shift)
    t2 = Recognizer(q1, q2)
    t3 = Translation(q2, q3)
    tt = Handler(q3)

    t1.set_file_path(file_path)
    t2.set_file_path(file_path)

    t1.start()
    t2.start()
    t3.start()
    tt.start()

    tt.join()